<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
    xmlns:kiwi="http://www.kiwi-project.eu/jsf"
    xmlns:c="http://java.sun.com/jstl/core"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:a="http://richfaces.org/a4j">

		<style>
	        .inplace{
	            border: none;
	            cursor:pointer; 
	        }
	        .hover {
	            color: #{a4jSkin.generalTextColor};
	            background-color :#{a4jSkin.tipBorderColor};
	        }   
		   
		   .typelist td {
		   		vertical-align: top;
		   }
	    </style> 
		
		<h1>Class perspective for<h:outputText value=" "/><h:outputText property="http://www.kiwi-project.eu/kiwi/core/title"/></h1>
		
		<p style="margin-top: 20px; margin-left: 10px; margin-right: 10px;" class="help">
		  The content item currently displayed represents either an RDFS or an OWL class. Using this perspective,
		  you can edit additional class related information about the content item, i.e. the sub- and superclasses, instances, etc.
		  Note that only explicit information (i.e. "base") can be edited. Inferred data is generated by reasoning rules out of other 
		  information. When hovering the mouse over inferred information, an explanation justifying its existance is displayed.
		</p>

		<br/>

		<!-- list of superclasses (needs proper layouting) -->
		<p:panel id="superclasses" header="Superclasses" footer="The currently displayed item is in a rdfs:subClassOf relation with the resources listed above.">
			<h:form>
	    		<strong>Base:</strong><br/>
		    	<c:forEach items="#{ontologyService.listSuperClasses(contentItem.resource,false)}" var="sc" varStatus="status">
		    		<h:outputLink value="#{configurationService.baseUri}/home.seam?kiwiid=#{kiwi.ui.utility.encodeURL(sc.kiwiIdentifier)}">
						<h:outputText value="#{sc.label} (#{sc.namespacePrefix})" />
					</h:outputLink>
					<h:commandLink action="#{ontologyService.removeSuperClass(contentItem.resource,sc)}">
						<h:graphicImage value="/img/type_delete.png" style="border: none;"/>
					</h:commandLink>
					<c:if test="#{not status.last}">,<h:outputText value=" "/></c:if>
		    	</c:forEach>
				<br/>
		    	<strong>Inferred:</strong><br/>
				<c:forEach items="#{ontologyService.listSuperClasses(contentItem.resource,true)}" var="sc" varStatus="status">
	                <s:link view="/home.xhtml" value="#{sc.label} (#{sc.namespacePrefix})"  propagation="none">
	                    <f:param name="title"/><f:param name="uri"/><f:param name="id" /><f:param name="kiwiid" value="#{sc.kiwiIdentifier}"/>
	                    <rich:toolTip attached="true" layout="block">
				            <f:facet name="defaultContent">
				                <strong>Please wait...</strong>
				            </f:facet>
	                
							<h:dataTable value="#{explanationService.explainTripleTextually(superclassTripleIds.get(sc), true)}" var="story">
							  <h:column>
			                	<h:outputText value="#{story.openingLine.body}" escape="false" style="font-weight:bold"/><h:outputText value=" #{story.openingLine.connective}" style="margin-left:5px"/>
			                	<br/>
							  	<h:dataTable value="#{story.body}" var="line">
							  		<h:column>
							  			<h:outputText value="#{line.body}" escape="false" style="font-weight:bold; margin-left:15px"/> <h:outputText value=" #{line.connective}" style="margin-left:5px"/> <br/>
							  		</h:column>
							  	</h:dataTable>
							  	<br/> <br/>
							  </h:column>
							</h:dataTable>						                
	                    </rich:toolTip>    
	                </s:link>
					<c:if test="#{not status.last}">,<h:outputText value=" "/></c:if>
		    	</c:forEach>			
				<br/>
		    	<strong>Add:</strong><br/>
				<p:autoComplete completeMethod="#{ontologyService.autocomplete}"
								value="#{kiwi.core.ui.classPerspectiveAction.selectedResource}"
				                var="resource" itemLabel="#{resource.label} (#{resource.namespacePrefix})"
								itemValue="#{resource}" forceSelection="true" converter="kiwiResourceConverter"/>
				<p:commandButton value="Add" action="#{kiwi.core.ui.classPerspectiveAction.addSuperclass}" ajax="false"/>
			</h:form>
		</p:panel>
		
		<br/>

		<!-- list of subclasses (needs proper layouting) -->
		<p:panel header="Subclasses" footer="The resources listed above are in a rdfs:subClassOf relation with the currently displayed item (max 100 resources shown).">
			<h:form>
	    		<strong>Base:</strong><br/>
		    	<c:forEach items="#{ontologyService.listSubClasses(contentItem.resource,false)}" var="sc" varStatus="status">
					<h:outputLink value="#{configurationService.baseUri}/home.seam?kiwiid=#{kiwi.ui.utility.encodeURL(sc.kiwiIdentifier)}">
						<h:outputText value="#{sc.label} (#{sc.namespacePrefix})" />
					</h:outputLink>
					<h:commandLink action="#{ontologyService.removeSuperClass(sc,contentItem.resource)}">
						<h:graphicImage value="/img/type_delete.png" style="border: none;"/>
					</h:commandLink>
					<c:if test="#{not status.last}">,<h:outputText value=" "/></c:if>
		    	</c:forEach>
				<br/>
		    	<strong>Inferred:</strong><br/>
		    	<c:forEach items="#{ontologyService.listSubClasses(contentItem.resource,true)}" var="sc" varStatus="status">
	                <s:link view="/home.xhtml" value="#{sc.label} (#{sc.namespacePrefix})"  propagation="none">
	                    <f:param name="title"/><f:param name="uri"/><f:param name="id" /><f:param name="kiwiid" value="#{sc.kiwiIdentifier}"/>
	                    <rich:toolTip attached="true" layout="block">
				            <f:facet name="defaultContent">
				                <strong>Please wait...</strong>
				            </f:facet>
	                
							<h:dataTable value="#{explanationService.explainTripleTextually(subclassTripleIds.get(sc), true)}" var="story">
							  <h:column>
			                	<h:outputText value="#{story.openingLine.body}" escape="false" style="font-weight:bold"/><h:outputText value=" #{story.openingLine.connective}" style="margin-left:5px"/>
			                	<br/>
							  	<h:dataTable value="#{story.body}" var="line">
							  		<h:column>
							  			<h:outputText value="#{line.body}" escape="false" style="font-weight:bold; margin-left:15px"/> <h:outputText value=" #{line.connective}" style="margin-left:5px"/> <br/>
							  		</h:column>
							  	</h:dataTable>
							  	<br/> <br/>
							  </h:column>
							</h:dataTable>						                
	                    </rich:toolTip>    
	                </s:link>
					<c:if test="#{not status.last}">,<h:outputText value=" "/></c:if>
		    	</c:forEach>
				<br/>
		    	<strong>Add:</strong><br/>
				<p:autoComplete completeMethod="#{ontologyService.autocomplete}"
								value="#{kiwi.core.ui.classPerspectiveAction.selectedResource}"
				                var="resource" itemLabel="#{resource.label} (#{resource.namespacePrefix})"
								itemValue="#{resource}" forceSelection="true" converter="kiwiResourceConverter"/>
				<p:commandButton value="Add" action="#{kiwi.core.ui.classPerspectiveAction.addSubclass}" ajax="false" />
			</h:form>
		</p:panel>

		<br/>

		<p:panel header="Instances" footer="The resources listed above are in a rdf:type relation with the currently displayed item (max 100 resources shown).">
			<h:form>
		    	<strong>Base:</strong><br/>
		    	<c:forEach items="#{ontologyService.listInstances(contentItem.resource,false)}" var="sc" varStatus="status">
		    		<h:outputLink value="#{configurationService.baseUri}/home.seam?kiwiid=#{kiwi.ui.utility.encodeURL(sc.kiwiIdentifier)}">
						<h:outputText value="#{sc.label} (#{sc.namespacePrefix})" />
					</h:outputLink>
					<h:commandLink action="#{ontologyService.removeInstance(contentItem.resource,sc)}">
						<h:graphicImage value="/img/type_delete.png" style="border: none;"/>
					</h:commandLink>
					<c:if test="#{not status.last}">,<h:outputText value=" "/></c:if>
		    	</c:forEach>
				<br/>
		    	<strong>Inferred:</strong><br/>
		    	<c:forEach items="#{ontologyService.listInstances(contentItem.resource,true)}" var="sc" varStatus="status">
	                <s:link view="/home.xhtml" value="#{sc.label} (#{sc.namespacePrefix})"  propagation="none">
	                    <f:param name="title"/><f:param name="uri"/><f:param name="id" /><f:param name="kiwiid" value="#{sc.kiwiIdentifier}"/>
	                    <rich:toolTip attached="true" layout="block">
				            <f:facet name="defaultContent">
				                <strong>Please wait...</strong>
				            </f:facet>
	                
							<h:dataTable value="#{explanationService.explainTripleTextually(instanceTripleIds.get(sc), true)}" var="story">
							  <h:column>
			                	<h:outputText value="#{story.openingLine.body}" escape="false" style="font-weight:bold"/><h:outputText value=" #{story.openingLine.connective}" style="margin-left:5px"/>
			                	<br/>
							  	<h:dataTable value="#{story.body}" var="line">
							  		<h:column>
							  			<h:outputText value="#{line.body}" escape="false" style="font-weight:bold; margin-left:15px"/> <h:outputText value=" #{line.connective}" style="margin-left:5px"/> <br/>
							  		</h:column>
							  	</h:dataTable>
							  	<br/> <br/>
							  </h:column>
							</h:dataTable>						                
	               		</rich:toolTip>    
	                </s:link>
					<c:if test="#{not status.last}">,<h:outputText value=" "/></c:if>
		    	</c:forEach>
				<br/>
		    	<strong>Add:</strong><br/>
				<p:autoComplete completeMethod="#{kiwi.core.ui.classPerspectiveAction.autocompleteResource}"
								value="#{kiwi.core.ui.classPerspectiveAction.selectedResource}"
				                var="resource" itemLabel="#{resource.label} (#{resource.namespacePrefix})"
								itemValue="#{resource}" forceSelection="true" converter="kiwiResourceConverter"/>
				<p:commandButton value="Add" action="#{kiwi.core.ui.classPerspectiveAction.addInstance}" ajax="false" />
			</h:form>
		</p:panel>
	        
</ui:composition>
